﻿using AnChao.WPF.Controls.Prism.Core;
using AnChao.WPF.Controls.Prism.Views;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnChao.WPF.Controls.Prism
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        IEventAggregator _eventAggregator;
        TickerSymbolSelectedEvent _event;

        public MainWindow()
        {
            InitializeComponent();
        }

        public MainWindow(IEventAggregator ea)
        {
            InitializeComponent();
            try
            {
                _eventAggregator = ea;
                _event = _eventAggregator.GetEvent<TickerSymbolSelectedEvent>();
                _event.Subscribe(ShowNews, ThreadOption.BackgroundThread, true);
            }
            catch (Exception ex)
            {
            }
        }

        private void btn1_Click(object sender, RoutedEventArgs e)
        {
            //_event.Publish("Stock0");
            MainWindowView fm = new MainWindowView();
            fm.ShowDialog();
        }

        void UnSubscribe()
        {
            _event.Unsubscribe(ShowNews);
        }

        private void ShowNews(string companySymbol)
        {

        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            UnSubscribe();
        }


    }
}
